//: Playground - noun: a place where people can play

import UIKit

// 让对象文本输出很简单，只要实现协议CustomStringConvertible 即可

class Person:CustomStringConvertible  {
    var name: String
    var age: Int
    var weight:Double
    init(name:String,age:Int,weight:Double) {
        self.name = name
        self.age = age
        self.weight = weight
    }
    var description: String{
        return name + String(age) + String(weight)
    }
}
let person = Person(name: "1111", age: 25,weight:150.0)
// 获取对象文本
let des = String(describing: person)
print(des)

// NSObject 里面已经实现了协议CustomStringConvertible,不能重复实现,我们只需要重写var description: String 即可

class Person1:NSObject {
    var name: String
    var age: Int
    var weight:Double
    init(name:String,age:Int,weight:Double) {
        self.name = name
        self.age = age
        self.weight = weight
    }
    override var description: String{
        return name + String(age) + String(weight)
    }
}

let person1 = Person1(name: "1111", age: 25,weight:150.0)
// 获取对象文本
let des1 = String(describing: person1)
print(des1)